package com.mydemo.game.hireStage.random;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class NameRandom {

    private static final List<String> surnameList = new ArrayList<>();
    private static final List<String> surnameList2 = new ArrayList<>();
    private static final List<String> maleNames = new ArrayList<>();
    private static final List<String> femaleNames = new ArrayList<>();
    private static final List<String> neutralNames = new ArrayList<>();
    private static final List<String> fixedNames = new ArrayList<>();
    private static final Random random = new Random();

    // 初始化姓氏列表（示例）
    static {
        String[] commonSurnames = {
                "赵", "钱", "孙", "李", "周", "吴", "郑", "王", "冯", "陈", "褚", "卫", "蒋", "沈", "韩",
                "杨", "朱", "秦", "尤", "许", "何", "吕", "施", "张", "孔", "曹", "严", "华", "金", "魏",
                "陶", "姜", "戚", "谢", "邹", "喻", "柏", "水", "窦", "章", "云", "苏", "潘", "葛", "奚",
                "范", "彭", "郎", "鲁", "韦", "昌", "马", "苗", "凤", "花", "方", "俞", "任", "袁", "柳"};
        for (String surname : commonSurnames) {
            surnameList.add(surname);
        }
        String[] commonSurnames2 = {
                "欧阳", "上官", "司马", "诸葛", "夏侯", "闻人", "东方", "赫连", "皇甫", "尉迟",
                "公羊", "澹台", "公冶", "宗政", "濮阳", "淳于", "单于", "太叔", "申屠", "公孙",
                "仲孙", "轩辕", "令狐", "钟离", "宇文", "长孙", "慕容", "鲜于", "闾丘", "司徒",
                "司空", "亓官", "司寇", "子车", "颛孙", "端木", "巫马", "公西", "漆雕", "乐正",
                "壤驷", "公良", "拓跋", "夹谷", "宰父", "谷梁", "晋楚", "闫法", "汝鄢", "涂钦",
                "段干", "百里", "东郭", "南门", "呼延", "羊舌", "微生", "梁丘", "左丘", "东门",
                "西门", "南宫", "北宫", "王孙", "公仪", "公乘", "公族", "公皙", "库狄", "房玄",
                "屠羊", "琴牢", "仲长", "有琴", "墨夷", "椒房", "吉白", "南宫", "高阳", "高辛",
                "青阳", "少昊", "颛顼", "涂山", "侯冈", "蜀王", "姒姓", "娄烦", "妘姓", "己姓",
                "董姓", "嬴姓", "子姓", "风姓", "曹姓", "妫姓", "姚姓", "姞姓", "妘姓", "偃姓",
                "皋陶", "狸姓", "妘讴", "祝融", "八姓", "妘苍", "姒参", "酉姓", "妊姓", "妘惠"  };
        for (String surname : commonSurnames2) {
            surnameList2.add(surname);
        }



        // 初始化男性名字列表（示例）
        String[] maleNameArray = {
                // 男性名字
                "伟", "刚", "勇", "毅", "俊", "峰", "强", "军", "平", "保", "东", "文", "辉", "力", "明",
                "永", "健", "世", "广", "志", "义", "兴", "良", "海", "山", "仁", "波", "宁", "贵", "福",
                "生", "龙", "元", "全", "国", "胜", "学", "祥", "才", "发", "武", "新", "利", "清", "飞",
                "彪", "宏", "德", "光", "天", "达", "安", "岩", "中", "茂", "进", "林", "有", "坚", "和",
                "彬", "柏", "松", "梵", "朋", "振", "鹤", "鹏", "雪", "霜", "星", "野", "涛", "羽", "翔",
                "剑", "雷", "锋", "树", "帆", "江", "河", "湖", "海", "洋", "波", "涛", "洪", "洲", "洋",
                "源", "鸿", "泽", "涵", "淇", "淳", "澜", "清", "澜", "源", "溟", "瀚", "灏", "瀚", "澎",
                "湃", "滨", "涛", "浚", "溟", "震", "霖", "文", "雨", "雷", "锋", "剑", "宏", "浩", "宇",
                "轩", "昂", "霖", "瀚", "文", "博", "宇", "翔", "海", "阳", "天", "俊", "驰", "宇", "泽"
        };
        for (String name : maleNameArray) {
            maleNames.add(name);
        }

        // 初始化女性名字列表（示例）
        String[] femaleNameArray = {
                "秀", "娟", "英", "华", "慧", "巧", "美", "娜", "静", "淑", "惠", "珠", "翠", "雅", "芝",
                "玉", "萍", "红", "娥", "玲", "芬", "芳", "燕", "彩", "春", "菊", "勤", "珍", "贞", "莉",
                "兰", "凤", "洁", "梅", "琳", "素", "云", "莲", "真", "环", "雪", "荣", "爱", "妹", "霞",
                "香", "月", "莺", "媛", "艳", "瑞", "凡", "佳", "嘉", "琼", "勤", "珍", "贞", "希", "湘",
                "琪", "莹", "珊", "欣", "妍", "婷", "姣", "茹", "雪", "娅", "媛", "怡", "婵", "娟", "娥",
                "妙", "秋", "倩", "君", "蕊", "蕾", "蓓", "薇", "蓝", "娅", "玥", "婷", "静", "姝", "瑛",
                "婉", "妍", "柔", "熙", "岚", "琳", "菲", "钰", "彤", "萱", "昕", "蕾", "欢", "霄", "娅",
                "澜", "纯", "毓", "悦", "昭", "冰", "爽", "琬", "茗", "羽", "希", "宁", "欣", "飘", "育",
                "馥", "筠", "柔", "竹", "霭", "凝", "晓", "欢", "霄", "娅", "黛", "曼", "语", "瑛", "瑶",

        };
        for (String name : femaleNameArray) {
            femaleNames.add(name);
        }

        // 初始化中性名字列表（示例）
        String[] neutralNameArray = {
                "晨", "曦", "煜", "磊", "晶", "鑫", "曦", "博", "睿", "思", "宇", "宸", "浩", "昊", "轩",
                "逸", "彤", "昕", "煜", "磊", "鹏", "辰", "逸", "晨", "曦", "晨", "熙", "煜", "煦", "煜",
                "昊", "磊", "博", "涛", "宇", "鹏", "煊", "烨", "煜", "熙", "然", "煜", "祺", "煜", "宸",
                "晨", "熙", "然", "烁", "灿", "煌", "煜", "炜", "熠", "彤", "煜", "煌", "烨", "伟", "烁",
        };
        for (String name : neutralNameArray) {
            neutralNames.add(name);
        }

        // 初始化限定名字列表
        String[] fixedNameArray = {"古月方源", "白凝冰", "异渡人", "萧十一郎", "藤原拓海"};
        for (String name : fixedNameArray) {
            fixedNames.add(name);
        }
    }

    /**
     * 生成一个随机姓名
     * @return 随机生成的姓名
     */
    public static String getRandomName() {
        // 生成名字长度
        int length = random.nextInt(100);
        String name = "";

        // 3%的概率生成限定名字
        if (length < 3) {
            name = fixedNames.get(random.nextInt(fixedNames.size()));
        } else {
            // 生成性别
            boolean isMale = random.nextDouble() < 0.65;
            boolean isFemale = !isMale && random.nextDouble() < (0.20 / (1.0 - 0.65));
            boolean isNeutral = !isMale && !isFemale; // 剩余概率为中性名字



            // 根据性别和长度生成名字部分
            if (length < 33 ) { // 30%的概率生成二字名字
                // 生成姓氏
                String surname = surnameList.get(random.nextInt(surnameList.size()));
                name = surname;
                if (isMale) {
                    name += maleNames.get(random.nextInt(maleNames.size()));
                } else if (isFemale) {
                    name += femaleNames.get(random.nextInt(femaleNames.size()));
                } else {
                    name += neutralNames.get(random.nextInt(neutralNames.size()));
                }
            } else if (length < 95) { // 62%的概率生成三字名字
                int i = random.nextInt(10);
                if(i>0){//姓氏为一个字
                    String surname = surnameList.get(random.nextInt(surnameList.size()));
                    name = surname;
                    String firstName;
                    String secondName;
                    if (isMale) {
                        firstName = maleNames.get(random.nextInt(maleNames.size()));
                        secondName = maleNames.get(random.nextInt(maleNames.size()));
                        // 为了避免重复，可以重新选择secondName直到它与firstName不同
                        while (firstName.equals(secondName)) {
                            secondName = maleNames.get(random.nextInt(maleNames.size()));
                        }
                    } else if (isFemale) {
                        firstName = femaleNames.get(random.nextInt(femaleNames.size()));
                        secondName = femaleNames.get(random.nextInt(femaleNames.size()));
                        while (firstName.equals(secondName)) {
                            secondName = femaleNames.get(random.nextInt(femaleNames.size()));
                        }
                    } else {
                        firstName = neutralNames.get(random.nextInt(neutralNames.size()));
                        secondName = neutralNames.get(random.nextInt(neutralNames.size()));
                        while (firstName.equals(secondName)) {
                            secondName = neutralNames.get(random.nextInt(neutralNames.size()));
                        }
                    }
                    name += firstName + secondName;

                }else {//姓氏为二个字
                    String surname = surnameList2.get(random.nextInt(surnameList2.size()));
                    name = surname;
                    if (isMale) {
                        name += maleNames.get(random.nextInt(maleNames.size()));
                    } else if (isFemale) {
                        name += femaleNames.get(random.nextInt(femaleNames.size()));
                    } else {
                        name += neutralNames.get(random.nextInt(neutralNames.size()));
                    }
                }

            } else { // 5%的概率生成四字名字
                int i = random.nextInt(10);
                if(i>5){//姓氏为一个字
                    String surname = surnameList.get(random.nextInt(surnameList.size()));
                    name = surname;
                    String firstName;
                    String secondName;
                    String thirdName;
                    if (isMale) {
                        firstName = maleNames.get(random.nextInt(maleNames.size()));
                        secondName = maleNames.get(random.nextInt(maleNames.size()));
                        thirdName = maleNames.get(random.nextInt(maleNames.size()));
                        while (firstName.equals(secondName)) {
                            secondName = maleNames.get(random.nextInt(maleNames.size()));
                        }
                        name += firstName + secondName + thirdName;
                    } else if (isFemale) {
                        firstName = femaleNames.get(random.nextInt(femaleNames.size()));
                        secondName = femaleNames.get(random.nextInt(femaleNames.size()));
                        thirdName = femaleNames.get(random.nextInt(femaleNames.size()));
                        while (firstName.equals(secondName)) {
                            secondName = femaleNames.get(random.nextInt(femaleNames.size()));
                        }
                        name += firstName + secondName + thirdName;
                    } else {
                        firstName = neutralNames.get(random.nextInt(neutralNames.size()));
                        secondName = neutralNames.get(random.nextInt(neutralNames.size()));
                        thirdName = neutralNames.get(random.nextInt(neutralNames.size()));
                        while (firstName.equals(secondName)) {
                            secondName = neutralNames.get(random.nextInt(neutralNames.size()));
                        }
                        name += firstName + secondName + thirdName;
                    }
                }else {//姓氏为二个字
                    String surname = surnameList2.get(random.nextInt(surnameList2.size()));
                    name = surname;
                    String firstName;
                    String secondName;
                    if (isMale) {
                        firstName = maleNames.get(random.nextInt(maleNames.size()));
                        secondName = maleNames.get(random.nextInt(maleNames.size()));
                        // 为了避免重复，可以重新选择secondName直到它与firstName不同
                        while (firstName.equals(secondName)) {
                            secondName = maleNames.get(random.nextInt(maleNames.size()));
                        }
                    } else if (isFemale) {
                        firstName = femaleNames.get(random.nextInt(femaleNames.size()));
                        secondName = femaleNames.get(random.nextInt(femaleNames.size()));
                        while (firstName.equals(secondName)) {
                            secondName = femaleNames.get(random.nextInt(femaleNames.size()));
                        }
                    } else {
                        firstName = neutralNames.get(random.nextInt(neutralNames.size()));
                        secondName = neutralNames.get(random.nextInt(neutralNames.size()));
                        while (firstName.equals(secondName)) {
                            secondName = neutralNames.get(random.nextInt(neutralNames.size()));
                        }
                    }
                    name += firstName + secondName;
                }

            }
        }
        // 返回生成的姓名
        return name;
    }
}